package com.atguigu.gulimail.order.controller;

import com.atguigu.gulimail.order.entity.OrderEntity;
import com.atguigu.gulimail.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
public class RabbitController {

    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("/sendMsg")
    public String sendMsg(@RequestParam(value = "num",defaultValue = "10")Integer num){
        for (int i=0;i<num;i++){
           if (i%2==0){
               OrderReturnReasonEntity orderReturnReasonEntity = new OrderReturnReasonEntity();
               orderReturnReasonEntity.setId(1L);
               orderReturnReasonEntity.setName("hh-"+i);

               rabbitTemplate.convertAndSend("java-test-exchange","java-test-queue",orderReturnReasonEntity,new CorrelationData(UUID.randomUUID().toString()));
           }else{
               OrderEntity orderEntity=new OrderEntity();
               orderEntity.setBillContent("googd-"+i);
               rabbitTemplate.convertAndSend("java-test-exchange","java-test-queue",orderEntity,new CorrelationData(UUID.randomUUID().toString()));
           }
        }
        return "hello world";
    }
}
